package com.coco.sharding;


import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

public class MySharding implements PreciseShardingAlgorithm<Long>{


    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Long> preciseShardingValue) {

        Long id = preciseShardingValue.getValue();
        System.out.println("user_id = "+id);
        long model = id % collection.size();
        String[] strings = collection.toArray(new String[0]);
        System.out.println("strings = "+strings);
        return strings[(int)model];
    }
}
